package com.aspose.cells;

import java.util.ArrayList;

class zef extends zbz {
   private ArrayList a;
   private int d = 0;

   zef() {
      this.c(90);
   }

   int a(zuq var1, ArrayList var2) {
      if (!var1.d()) {
         return 0;
      } else {
         int var3 = ((zum)var2.get(0)).a;
         int var4 = ((zum)var2.get(var2.size() - 1)).a;
         int var5 = var4 - var3 + 1;
         var5 *= 9;

         for(int var6 = 0; var6 < var2.size(); ++var6) {
            zum var7 = (zum)var2.get(var6);
            if (var7.b() == 2) {
               var5 -= 9;
               String var8 = com.aspose.cells.b.a.zr.a(var7.b);
               if (zakq.f(var8)) {
                  var5 += 4 + var8.length();
               } else {
                  var5 += 4 + var8.length() * 2;
               }
            }
         }

         var5 += 4;
         return var5;
      }
   }

   private zbz a(zbz var1, int[] var2) {
      var1.a((short)var2[0]);
      this.d -= var2[0];
      var2[0] = 0;
      zmo var3 = new zmo();
      Object var4 = null;
      byte[] var5;
      if (this.d < 8224) {
         var5 = new byte[this.d];
      } else {
         var5 = new byte[8224];
      }

      var3.b(var5);
      com.aspose.cells.b.a.a.ze.a(this.a, (Object)var3);
      return var3;
   }

   void a(zuq var1) {
      ArrayList var2 = var1.f();
      this.d = this.a(var1, var2);
      int var5;
      if (this.d > 8224) {
         byte[] var3 = this.c = new byte[8224];
         Object var4 = this;
         this.a = new ArrayList();
         var5 = 4;
         this.c[0] = (byte)var1.b();
         this.c[1] = (byte)var1.e();
         System.arraycopy(com.aspose.cells.b.a.zc.a(var1.a()), 0, this.c, 2, 2);

         for(int var6 = 0; var6 < var2.size(); ++var6) {
            zum var7 = (zum)var2.get(var6);
            if (var7.b() == 2) {
               String var8 = com.aspose.cells.b.a.zr.a(var7.b);
               byte[] var9 = zakq.a(var8);
               if (var5 + 4 + var9.length > var3.length) {
                  int[] var10 = new int[]{var5};
                  var4 = this.a((zbz)var4, (int[])var10);
                  var5 = var10[0];
                  var3 = ((zbz)var4).e();
               }

               var3[var5] = 2;
               System.arraycopy(com.aspose.cells.b.a.zc.a(var8.length()), 0, var3, var5 + 1, 2);
               var3[var5 + 3] = 0;
               if (var9 == null) {
                  continue;
               }

               var5 += 3;
               int var23 = 0;
               int var11 = var3.length - var5;
               int var12 = var9.length - var23 + 1;
               boolean var13 = var9.length == var8.length();
               if (var11 >= var12) {
                  var3[var5] = (byte)(var13 ? 0 : 1);
                  ++var5;
                  System.arraycopy(var9, 0, var3, var5, var9.length);
                  var5 += var9.length;
                  continue;
               }

               for(boolean var14 = true; var11 < var12; var12 = var9.length - var23) {
                  if (var14) {
                     var3[var5] = (byte)(var13 ? 0 : 1);
                     ++var5;
                     --var11;
                     if (var13 && var11 % 2 != 0) {
                        --var11;
                     }

                     var14 = false;
                  }

                  System.arraycopy(var9, var23, var3, var5, var11);
                  var23 += var11;
                  var5 += var11;
                  int[] var15 = new int[]{var5};
                  var4 = this.a((zbz)var4, (int[])var15);
                  var5 = var15[0];
                  var3 = ((zbz)var4).e();
                  var5 = 0;
                  var11 = var3.length - var5;
               }

               System.arraycopy(var9, var23, var3, var5, var12);
               int var10000 = var23 + var12;
               var5 += var12;
            } else if (var5 + 9 > var3.length) {
               int[] var20 = new int[]{var5};
               var4 = this.a((zbz)var4, (int[])var20);
               var5 = var20[0];
               var3 = ((zbz)var4).e();
            }

            if (var7.b == null) {
               var5 += 9;
            } else {
               switch(var7.b()) {
               case 0:
                  var5 += 9;
                  break;
               case 1:
                  var3[var5] = 1;
                  System.arraycopy(com.aspose.cells.b.a.zc.a(var7.c()), 0, var3, var5 + 1, 8);
                  var5 += 9;
                  break;
               case 2:
               default:
                  if (var7.b instanceof zst) {
                     var3[var5] = 16;
                     this.a((zst)var7.b, var3, var5);
                     var5 += 9;
                  }
                  break;
               case 3:
                  this.c[var5] = 16;
                  this.a(var7.d(), this.c, var5);
                  var5 += 9;
                  break;
               case 4:
                  var3[var5] = 4;
                  if (var7.e()) {
                     var3[var5 + 1] = 1;
                  }

                  var5 += 9;
               }
            }
         }
      } else {
         this.a((short)this.d);
         this.c = new byte[this.d];
         int var16 = 4;
         this.c[0] = (byte)var1.b();
         this.c[1] = (byte)var1.e();
         int var17 = (this.c[1] & 255) - 1;
         System.arraycopy(com.aspose.cells.b.a.zc.a(var1.a()), 0, this.c, 2, 2);

         for(var5 = 0; var5 < var2.size(); ++var5) {
            zum var18 = (zum)var2.get(var5);
            if (var17 + 1 != var18.a) {
               var16 += (var18.a - var17 - 1) * 9;
            }

            var17 = var18.a;
            if (var18.b == null) {
               var16 += 9;
            } else {
               switch(var18.b()) {
               case 0:
                  var16 += 9;
                  break;
               case 1:
                  this.c[var16] = 1;
                  System.arraycopy(com.aspose.cells.b.a.zc.a(var18.c()), 0, this.c, var16 + 1, 8);
                  var16 += 9;
                  break;
               case 2:
               default:
                  String var19 = com.aspose.cells.b.a.zr.a(var18.b);
                  boolean var21 = false;
                  boolean[] var22 = new boolean[]{var21};
                  zst var24 = zsk.a(var19, var22);
                  var21 = var22[0];
                  if (var21 && var24 != zst.h) {
                     this.c[var16] = 16;
                     this.a(var24, this.c, var16);
                     var16 += 9;
                  } else {
                     this.c[var16] = 2;
                     byte[] var25 = zakq.a(var19);
                     if (var25 == null) {
                        this.c[var16 + 3] = 0;
                        var16 += 4;
                     } else {
                        if (var25.length == var19.length()) {
                           System.arraycopy(com.aspose.cells.b.a.zc.a(var19.length()), 0, this.c, var16 + 1, 2);
                           this.c[var16 + 3] = 0;
                           System.arraycopy(var25, 0, this.c, var16 + 4, var25.length);
                        } else {
                           System.arraycopy(com.aspose.cells.b.a.zc.a(var19.length()), 0, this.c, var16 + 1, 2);
                           this.c[var16 + 3] = 1;
                           System.arraycopy(var25, 0, this.c, var16 + 4, var25.length);
                        }

                        var16 += 4 + var25.length;
                     }
                  }
                  break;
               case 3:
                  this.c[var16] = 16;
                  this.a(var18.d(), this.c, var16);
                  var16 += 9;
                  break;
               case 4:
                  this.c[var16] = 4;
                  if (var18.e()) {
                     this.c[var16 + 1] = 1;
                  }

                  var16 += 9;
               }
            }
         }
      }

   }

   private void a(zst var1, byte[] var2, int var3) {
      switch(null.a[var1.ordinal()]) {
      case 1:
         this.c[var3 + 1] = 7;
         break;
      case 2:
         this.c[var3 + 1] = 42;
         break;
      case 3:
         this.c[var3 + 1] = 29;
         break;
      case 4:
         this.c[var3 + 1] = 0;
         break;
      case 5:
         this.c[var3 + 1] = 36;
         break;
      case 6:
         this.c[var3 + 1] = 23;
         break;
      case 7:
         this.c[var3 + 1] = 15;
      }

   }

   void a(zqa var1) throws Exception {
      var1.a(this.f());
      var1.a(this.d());
      var1.a(this.c, 0, this.d());
      if (this.a != null) {
         for(int var2 = 0; var2 < this.a.size(); ++var2) {
            zmo var3 = (zmo)this.a.get(var2);
            var3.a(var1);
         }
      }

   }
}
